# -*- coding: utf-8 -*-
import redis
from conf.variable import REDIS_CONFIG


class RedisCnxPool:
    def __init__(self):
        redis_pool = redis.ConnectionPool(
            host=REDIS_CONFIG['host'],
            port=REDIS_CONFIG['port'],
            password=REDIS_CONFIG['password'],
            db=REDIS_CONFIG['db'])
        self.redis_conn = redis.Redis(connection_pool=redis_pool)

    def get_conn(self):
        return self.redis_conn


if __name__ == '__main__':
    redis_conn = RedisCnxPool().get_conn()
    m = redis_conn.set(name='CDSS-HELLO', value='你好，Redis！', ex=10)
    value = redis_conn.get(name='CDSS-HELLO')
    value = str(value, encoding='utf-8') if value is not None else value
    print('ok')
